package com.zhang.dao.impl;

import com.zhang.dao.PlayInfoDao;
import com.zhang.domain.PlayInfo;
import com.zhang.domain.User;
import com.zhang.util.JDBCUtils;
import org.junit.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class PlayInfoDaoImpl implements PlayInfoDao {
    private JdbcTemplate jdbcTemplate =  new JdbcTemplate(JDBCUtils.getDataSource());

    @Override
    public int enterPlayInfo(PlayInfo playInfo) {
        String sql = "INSERT INTO `play_info` VALUES(NULL,?,?,?,?,?,?,?)";
        return  jdbcTemplate.update(sql, playInfo.getPlayName(), playInfo.getAttack(), playInfo.getArmor(), playInfo.getSpeed(), playInfo.getOccupation(), playInfo.getSkill(), playInfo.getUid());

    }

    @Override
    public int updatePlayInfo(PlayInfo playInfo) {
        String sql = "UPDATE  `play_info`  SET `playName` = ?,`Attack` = ?, `Armor` = ?,`speed` = ?, `occupation` = ?,`skill` = ?  WHERE `uid` = ?";
        return  jdbcTemplate.update(sql, playInfo.getPlayName(), playInfo.getAttack(), playInfo.getArmor(), playInfo.getSpeed(), playInfo.getOccupation(), playInfo.getSkill(), playInfo.getUid());
    }

    @Override
    public PlayInfo getPlayInfoByUid(int uid) {
        String sql = "SELECT * FROM `play_info` WHERE uid = ?";
        PlayInfo playInfo = null;
        try {
            playInfo = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<PlayInfo>(PlayInfo.class), uid);
        } catch (DataAccessException e) {

        }

        return playInfo;
    }



}


























